<template>
    <div class="container">
        <div class="banner-set">
            <header>
                <router-link to="/">首页 / </router-link>
                <router-link to="">运营管理 / </router-link>
                banner配置
            </header>
            <div v-if="messageList.length > 0" class="focus-pointer mb30">
                <div class="flex-box-align" style="padding-left: 18px; position: relative; width: 100%;">
                    今日要事：
                    <div class="message">
                        <ul class="marquee_list" :style="{ top: -num + 'px'}" :class="{marquee_top:num}">
                            <li v-for="(item, index) in messageList" :key="index" v-if="messageList && messageList.length">
                                <router-link :to="{name: item.route}">{{item.showMsg}}</router-link>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="">
                <div style="background-color: #fff;padding: 11px 20px;">
                    首页banner配置
                    <el-button type="primary" style="background-color: #ED7018;border-color: #ED7018;margin-left: 10px;" @click="handleAddBanner">添加banner</el-button>
                </div>
                <table-list ref="tableList" :tableConfig='configList'>

                    <el-table-column  slot=""  align="center" label="">
                        <template slot-scope="scope">
                            <span></span>
                        </template>
                    </el-table-column>
                    <el-table-column  slot="image"  align="center" label="banner图片">
                        <template slot-scope="scope">
                            <div>
                                <img :src="scope.row.imageList[0].fileUrl" alt="" style="width: 120px">
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column class="btn" label="操作" slot="btn" align="center" >
                        <template slot-scope="scope">
                            <!--<el-button  type="primary" size="small" style="background: #A0A0A0;border-color:#A0A0A0">-->
                                <!--<router-link :to="{ path: '/partner/companyDetail', query: {id:scope.row.id}}"  style="color: #fff;">编辑</router-link>-->
                            <!--</el-button>-->
                            <!--<el-button  type="primary" size="small" @click="handleClickOn(scope.row.id)" v-if="scope.row.auditStatus == 'reject'">上架</el-button>-->
                            <!--<el-button  type="primary" size="small" @click="handleClickOff(scope.row.id)" style="background: #ED7018;border-color: #ED7018" v-else-if="scope.row.auditStatus == 'pass'">下架</el-button>-->
                            <!-- <el-button  type="primary" size="small" style="background: #A0A0A0;border-color:#A0A0A0">
                                <router-link :to="{ path: '/operate/bannerSet', query: {id:scope.row.userId}}"  style="color: #fff;">编辑</router-link>
                            </el-button> -->
                             <el-button @click="$router.push('/operate/bannerEdit?id='+scope.row.id)"  type="primary" size="small">编辑</el-button>
                             <el-button @click="deleteBanner(scope.row.id)" type="danger" size="mini">删除</el-button>
                        </template>
                    </el-table-column>
                </table-list>
            </div>
        </div>
    </div>
</template>

<script>
    import {parseUrlParams} from "../../util";
    let CONSTANT = require('../../constant/constant.js'),
        common = require('../../common.js');
    export default {
        data() {
            return {
                singleInvestMoneyList: [],
                investTypeList: [],
                firstIndustryList: [],
                fundBodyList: [],
                financeLevelList: [],
                investList: [],
                props: {
                    label: "value",
                    value: 'key',
                    children: 'childs'
                },

                selectedOptions: [],

                configList:{
                    url:CONSTANT.URL.BANNER.BANNERLIST,
                    configList:[
                        {
                            label:'banner标题',
                            prop: "title",
                        },
                        {
                            slot: "image"
                        },
                        {
                            label:'生效日期',
                            prop: "gmtCreated"
                        },
                        {
                            label:'添加人',
                            prop: ""
                        },
                        {
                            slot:'btn'
                        }
                    ],
                    param:{
                        investType: "",
                        singleInvestFund: "",
                        regCityCode: "",
                        regProvinceCode: "",
                        fundBody: "",
                        financeLevel: "",
                        investYear: "",
                        firstIndustry: "",
                        secondIndustry: "",
                        thirdIndustry: "",
                    },
                    type:'',
                    width:'',
                    isPagination:true
                },


                auditStatusList: [
                    {
                        value: "init",
                        label: "待审核"
                    },
                    {
                        value: "pass",
                        label: "已审核"
                    },
                    {
                        value: "reject",
                        label: "拒绝"
                    }
                ],
                num: 0,
                messageList: []
            }
        },
        components: {
            'table-list':() => import('../common/my-table')
        },
        mounted(){
            this.getMessage()
            setInterval( () => {
                this.getMessage()
            }, 120000)
        },
        methods:{
            getMessage() {
                let url = CONSTANT.URL.CALENDAR.MESSAGELIST;
                common.requestAjax(url, {}, {}, (data) => {
                    if(data.status == 200) {
                        this.messageList = data.data.bussData;
                        this.showMarquee(this.num)
                    }
                })
            },
            deleteBanner(id){
                this.$confirm('确认删除该试卷?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let url = CONSTANT.URL.BANNER.DELETEBANNER;
                     common.requestAjax(url, {}, {id:id}, (res)=>{
                            this.$message({ type: 'success', message: res.msg });
                            this.$refs.tableList.getList()
                    }); 
                }).catch(() => {
                    this.$message({  type: 'info', message: '已取消删除' });          
                });
                
            },
            getDictionary(params, callback) {
                let url = CONSTANT.URL.SYS.LOADDICTIONARY;
                common.requestAjax(url, {codeType: params}, {}, callback);
            },
            getUserType(params, callback) {
                let url = CONSTANT.URL.COMPANY.USERTYPE;
                common.requestAjax(url, {UserType: params}, {}, callback)
            },
            handleAddBanner() {
                this.$router.push("/operate/bannerEdit")
            },
            showMarquee:function (num) {
                if (!this.messageList[0]) return
                this.messageList.push(this.messageList[0]);
                var max = this.messageList.length;
                var that = this;
                let marqueetimer =  setInterval(function(){
                    num++;
                    if(num>=max ){
                        num=0;
                    }
                    that.num=num*30;
                }, 2000);
            }
        }
    }
</script>

<style lang="scss" scoped>
    .message {
        display: block;
        position: relative;
        width: 60%;
        height: 30px;/*关键样式*/
        overflow: hidden;
    }
    .marquee_list{
        display: block;
        position: absolute;
        top:0;
        left: 0;
    }
    .marquee_top{transition: top 0.5s ;}/*关键样式*/
    .marquee_list li{
        height: 30px;/*关键样式*/
        line-height: 30px;/*关键样式*/
        font-size: 14px;
        padding-left: 20px;
        background-color: #fff;
        a {
            color: #333;
        }
    }
    .container {
        .mb30 {
            margin-bottom: 30px;
        }
        .banner-set {
            header {
                margin: 19px 0;
                font-size: 14px;
                color: #333;
                a {
                    color: #999;
                }
            }
            .focus-pointer {
                font-size: 14px;
                height: 70px;
                line-height: 70px;
                background-color: #fff;
                padding-left: 18px;
                white-space: nowrap;
            }
            .search-modal {
                background: #fff;
                padding: 20px 0 25px 18px;
                .btns {
                    width: 73px;
                    height: 40px;
                    text-align: center;
                    line-height: 40px;
                    color: #fff;
                    font-size: 14px;
                    border-radius: 4px;
                    background-color: #ED7018;
                    display: inline-block;
                }
                .btn-search {
                    margin: 0 20px 0 24px;
                }
                .search-item {
                    /*width: 25%;*/
                    /*display: inline-block;*/
                    /*margin-right: 2.56%;*/
                    margin-right: 3.6%;
                    margin-bottom: 30px;
                    &:last-child {
                        margin-right: 0;
                    }
                    .search-title {
                        display: inline-block;
                    }
                    .el-input {
                        display: inline-block;
                    }
                    .el-select {
                        width: 54%;
                    }
                }
            }
        }
    }
</style>
